package org.reward;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author: xwg
 * @CreateDate: 2021/11/27
 */

// 设计与用户交互的代码 scanner UI
public class Client {
    public void welcome() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请用户输入账号名字：");
        String name = scanner.next();
        System.out.println("欢迎" + name);
        Integer goldCoin = 1000;
        Integer countYellow = 0;
        Integer countPurple = 0;
        Integer countGold = 0;

        for (int i = 0; i < 100; i++) {
            System.out.println("***********************************************");
            System.out.println(
                    String.format("===金币：%d  黄色蛋糕%d个 紫色蛋糕%d个 金色蛋糕%d个 ",
                            goldCoin, countYellow, countPurple, countGold));
            System.out.println("***********************************************");
            System.out.println("**操作菜单*****88十连抽(a)*******退出(q)**********");
            System.out.println("***********************************************");

            String command = scanner.next();
            if (command.equals("a")) {
                if (goldCoin < 88) {
                    System.out.println("当前金币数量不够，请充值");
                } else {
                    Core core = new Core();
                    String[] results = core.produceTen();
                    System.out.println(Arrays.toString(results));
                    goldCoin = goldCoin - 88;

                    Integer incrementYellow = 0;
                    Integer incrementPurple = 0;
                    Integer incrementGold = 0;
                    for (int j = 0; j < results.length; j++) {
                        if (results[j].startsWith(Core.YELLOW)) {
                            incrementYellow++;
                        } else if (results[j].startsWith(Core.PURPLE)) {
                            incrementPurple++;
                        } else if (results[j].startsWith(Core.GOLD)) {
                            incrementGold++;
                        }
                    }
                    countYellow = countYellow + incrementYellow;
                    countPurple = countPurple + incrementPurple;
                    countGold = countGold + incrementGold;

                }

            } else if (command.equals("q")) {
                System.out.println("正在退出系统。。。");
                i = 1000;
            }
        }
    }

    public static void main(String[] args) {
        Client client = new Client();
        client.welcome();
    }
}
